package day4.HomeWork;

import java.util.Arrays;

public class Test3 {
    /*
    编写一个静态方法print2DArray，接收任意类型的二维数组作为参数，返回与Arrays.toString()格式类似的字符串。
    要求：
    (1)支持int[][]、String[][]等常见数据类型
    (2)正确处理空数组、null元素等边界情况
    (3)输出格式示例：[[1, 2], [3, 4], [5]]
    */
    public static void print2DArray(int[][] array){
        if(array==null){
            System.out.println("null");
            return ;
        }
        if(array.length==0){
            System.out.println("[]");
            return;
        }
        System.out.print("[");
        for (int i = 0; i < array.length ; i++) {
            System.out.print(Arrays.toString(array[i]));
            if(i<array.length-1){
                System.out.print(",");
            }
        }
        System.out.println("]");
    }
    public static void print2DArray(String[][] array){
        if(array==null){
            System.out.println("null");
            return ;
        }
        if(array.length==0){
            System.out.println("[]");
            return;
        }
        System.out.print("[");
        for (int i = 0; i < array.length ; i++) {
            System.out.print(Arrays.toString(array[i]));
            if(i<array.length-1){
                System.out.print(",");
            }
        }
        System.out.println("]");
    }

    public static void main(String[] args) {
        int[][] arr1 = {{1,2},{3,4},{5}};
        print2DArray(arr1);
        String[][] arr2 = {{"hello","world"},{"my","friend"},{"!"}};
        print2DArray(arr2);
        int[][] arr3={};
        print2DArray(arr3);
        int[][] arr4=null;
        print2DArray(arr4);
    }
}
